package leetcode;

import java.util.Arrays;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-02-11 17:08
 **/
public class LeetCode1984 {

    public int minimumDifference(int[] nums, int k) {
        Arrays.sort(nums);
        int res = Integer.MAX_VALUE;
        for (int i = 0; i + k - 1 < nums.length; ++i) {
            res = Math.min(nums[i + k - 1] - nums[i], res);
        }
        return res;
    }

}
